<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('横向课题列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>申请人：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>课题名称：</label>
                                <input type="text" name="topName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="state" th:with="type=${@dict.getType('sci_crosswise_tasks')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:apply:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="system:apply:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:apply:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:apply:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var proFlag = [[${@permission.hasPermi('system:apply:process')}]];
        var editFlag = [[${@permission.hasPermi('system:apply:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:apply:remove')}]];
        var editInfo = [[${@permission.hasPermi('system:apply:info')}]];
        var hechaFlag = [[${@permission.hasPermi('system:apply:hecha')}]];
        var topTypeDatas = [[${@dict.getType('sci_top_type')}]];
        var datas = [[${@dict.getType('sci_crosswise_tasks')}]];

        var prefix = ctx + "system/apply";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                detailUrl: prefix + "/detail/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "横向课题",
                sortOrder: "asc",
                columns: [{
                    field: 'number',
                    title: '序号',
                    width:5 ,
                    align:'center',
                    switchable:false,
                    formatter:function(value,row,index){
                        //return index+1; //序号正序排序从1开始

                        //通过表的#id 可以得到每页多少条
                        var pageSize=$('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //通过表的#id 可以得到当前第几页
                        var pageNumber=$('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                    {
                        field: 'yname',
                        align: 'center',
                        title: '学院'
                    },
                    {
                        field: 'dname',
                        align: 'center',
                        title: '专业'
                    },
                {
                    field: 'userName',
                    align: 'center',
                    title: '申请人'
                },
                {
                    field: 'topName',
                    align: 'center',
                    title: '课题名称'
                },
                // {
                //     field: 'topType',
                //     title: '课题类型',
                //     formatter: function(value, row, index) {
                //        return $.table.selectDictLabel(topTypeDatas, value);
                //     }
                // },

                {
                    field: 'signingData',
                    align: 'center',
                    title: '签订日期'
                },
                {
                    field: 'amount',
                    align: 'center',
                    title: '项目金额'
                },
                  {
                        field: 'state',
                        title: '状态',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(datas, value);
                        }
                   }  ,
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                        if(row.state == 1 ){
                             if(row.userId == row.uid){
                                 actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                 actions.push('<a   class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>更新</a> ');
                             }

                            actions.push('<a  class="btn btn-success btn-xs ' + proFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id+'/pro' + '\')"><i class="fa fa-edit"></i>批阅</a> ');

                        }else
                        if((row.state == 3 || row.state == 5)  && row.userId == row.uid){
                            actions.push('<a   class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>更新</a> ');
                        }else if(row.state ==  2){

                            actions.push('<a  class="btn btn-success btn-xs ' + hechaFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id +'/hecha'+ '\')"><i class="fa fa-edit"></i>核查</a> ');
                        }else
                        if(row.state ==  4){

                            actions.push('<a  class="btn btn-success btn-xs ' + editInfo + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id +'/chakan'+ '\')"><i class="fa fa-edit"></i>查看</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

        });
    </script>
</body>
</html>